from util.selenium.webdriver.common.by import By

from base.BaseMethod import BM


class IARdmDesc():
    form_btn_loc = (By.LINK_TEXT, '研究开发与技术创新组织管理情况')
    rdm_desc_loc = (By.CSS_SELECTOR, 'textarea#Jscxgl')
    save_btn_loc = (By.CSS_SELECTOR, 'button#dataEprCycxSave')
    # # # 该页面共有四个附件上传按钮
    # upload_btn1_loc = (By.CSS_SELECTOR, '.box-body div:nth-of-type(1)%s')
    # upload_btn2_loc = (By.CSS_SELECTOR, '.box-body div:nth-of-type(2)%s')
    # upload_btn3_loc = (By.CSS_SELECTOR, '.box-body div:nth-of-type(3)%s')
    # upload_btn4_loc = (By.CSS_SELECTOR, '.box-body div:nth-of-type(4)%s')
    btn1 = '.box-body div:nth-of-type(1) .main'
    btn2 = '.box-body div:nth-of-type(2) .main'
    btn3 = '.box-body div:nth-of-type(3) .main'
    btn4 = '.box-body div:nth-of-type(4) .main'

    css = By.CSS_SELECTOR

    tip_str = " div.title"
    btn_str = " .btnBox a"

    def __init__(self, driver=None, text=''):
        self.driver = driver
        self.text = text

    @property
    def class_name(self):
        return self.__class__.__name__

    def upload_file(self):
        BM.click_upload(btn_loc=(self.css, self.btn1 + self.btn_str), tip_loc=(self.css, self.btn1 + self.tip_str),
                        driver=self.driver, class_name=self.class_name)
        BM.click_upload(btn_loc=(self.css, self.btn2 + self.btn_str), tip_loc=(self.css, self.btn2 + self.tip_str),
                        driver=self.driver, class_name=self.class_name)
        BM.click_upload(btn_loc=(self.css, self.btn3 + self.btn_str), tip_loc=(self.css, self.btn3 + self.tip_str),
                        driver=self.driver, class_name=self.class_name)
        BM.click_upload(btn_loc=(self.css, self.btn4 + self.btn_str), tip_loc=(self.css, self.btn4 + self.tip_str),
                        driver=self.driver, class_name=self.class_name)


    def fill_form(self):
        self.driver.find_element(*self.form_btn_loc).click()
        BM.click(driver=self.driver, ele_loc=self.form_btn_loc)
        BM.wait(driver=self.driver, ele_loc=self.rdm_desc_loc)
        BM.input(driver=self.driver, ele_loc=self.rdm_desc_loc, keys=self.text)
        # TODO 上传附件

        BM.global_click_btn(btn_loc=self.save_btn_loc, driver=self.driver)


if __name__ == '__main__':
    a = IARdmDesc
    # print((a.css, a.btn1 + a.btn_str))
    print((a.css, a.btn1 + a.tip_str))
    # b = (a.upload_btn1_loc[1] + a.tip_str)
    # c = a.upload_btn1_loc[1] + a.btn_str
    # print(a.upload_btn1_loc % a.tip_str)
    # print(b)
    # print(c)
